package app.v1.common.domain.ao.resource;

import com.gitee.feizns.quickstart.validation.Verifiable;
import com.gitee.feizns.quickstart.validation.constraints.DynamicValidate;
import com.gitee.feizns.quickstart.web.ex.BadRequestException;
import app.v1.common.domain.pojo.Resource;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotNull;

/**
 * 资源创建请求参数
 * @author feizns
 * @since 2023/06/11
 */
@Data
@DynamicValidate
public class ResourceCreateAo implements Verifiable {

    /**
     * 文件
     */
    @NotNull
    private MultipartFile file;

    /**
     * 资源类型（file=文件、video=视频、audio=音频、image=图片）
     */
    private Resource.Type type = Resource.Type.file;

    @Override
    public boolean validate() {
        if ( file.isEmpty() )
            throw new BadRequestException("文件不能为空.");
        return true;
    }

}
